﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace xpe
{
    public enum ParticleType { Point, Line, Triangle, Quad }

    public class Particle
    {
        /// <summary>
        /// The type of this particle
        /// </summary>
        protected ParticleType type;

        /// <summary>
        /// The texture
        /// </summary>
        protected Texture2D texture;

        /// <summary>
        /// The start color
        /// </summary>
        protected Color start;

        /// <summary>
        /// The end color
        /// </summary>
        protected Color end;

        /// <summary>
        /// The mass
        /// </summary>
        protected float mass;

        /// <summary>
        /// The life time in seconds
        /// </summary>
        protected float life;

        /// <summary>
        /// Create a new particle with the specifed type and texture
        /// </summary>
        /// <param name="type">The type of particle</param>
        /// <param name="texture">The texture of the particle</param>
        public Particle(ParticleType type, Texture2D texture)
        {
            if (texture == null)
                throw new ArgumentNullException("texture == null");

            this.type = type;
            this.texture = texture;

            start = Color.White;
            end = new Color(1f, 1f, 1f, 0f);

            mass = 1f;
            life = 2f;
        }

        /// <summary>
        /// The type of particle
        /// </summary>
        public ParticleType Type
        {
            get { return type; }
            set { type = value; }
        }

        /// <summary>
        /// The texture
        /// </summary>
        public Texture2D Texture
        {
            get { return texture; }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value == null");

                texture = value;
            }
        }

        /// <summary>
        /// The start color for this particle
        /// </summary>
        public Color StartColor
        {
            get { return start; }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value == null");

                start = value;
            }
        }

        /// <summary>
        /// The end color for this particle
        /// </summary>
        public Color EndColor
        {
            get { return end; }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value == null");

                end = value;
            }
        }

        /// <summary>
        /// The mass of this particle
        /// </summary>
        public float Mass
        {
            get { return mass; }
            set
            {
                if (mass <= 0f)
                    throw new ArgumentException("mass <= 0f");

                mass = value;
            }
        }

        /// <summary>
        /// The life time for this particle in seconds
        /// </summary>
        public float LifeTime
        {
            get { return life; }
            set
            {
                if (life < 0f)
                    life = 0f;

                life = value;
            }
        }   
    }
}
